var common = require('../../utils/commonUtil.js');
const {requestHome} = require('../../utils/netUtils.js');
Page({
    onShareAppMessage() {
        return {
            title: '越艺术 悦生活',
            path: 'pages/home/index'
        }
    },
    data: {
        swiperItems:  [],
        newExList: [],
        wantList: [],
        recommendList: [],
        imagePrefix: common.imagePrefix
    },
  onLoad: function (option) {
      requestHome(res=>{
          console.log({type:'主页接口数据返回',res});
          if(res.status==='200'){
              let  recommendList = res.data.isRecommendList.slice(0,10);
              recommendList.map(item=>{
                  let timeStrObj = common.timeUtil.genStartEndTime(item.startTime,item.endTime);
                  item.startTime =timeStrObj.start;
                  item.endTime = timeStrObj.end;
              });
              let swiperItems = this.data.swiperItems;
              if(res.data.banner&&res.data.banner.length>0){
                  swiperItems= res.data.banner;
              }
              this.setData({
                  swiperItems,
                  newExList:res.data.newZhanxunList.slice(0,10),
                  recommendList,
                  wantList:res.data.wantList.slice(0,10),
                  wantListCount:res.data.wantListCount||0,
                  isRecommendListCount:res.data.isRecommendListCount||0,
                  newZhanxunListCount:res.data.newZhanxunListCount||0,
              });
          }else{
              common.toast(res.msg,'none');
          }
      });
  },

  onReady: function () {
      setTimeout(()=>{this.setData({
          op: 1,
          mr:0
      })},400);
  },
  onShow: function () {
  },
  onHide: function () {
  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {
      requestHome(res=>{
          if(res.status==='200'){
              let  recommendList = res.data.isRecommendList.slice(0,10);
              recommendList.map(item=>{
                  item.startTime = common.timeUtil.formatTime(item.startTime,'Y.M.D');
                  item.endTime = common.timeUtil.formatTime(item.endTime,'M.D');
              });
              let swiperItems = res.data.banner;
              this.setData({
                  //swiperItems,
                  newExList:res.data.newZhanxunList.slice(0,10),
                  recommendList,
                  wantList:res.data.wantList.slice(0,10),
                  wantListCount:res.data.wantListCount||0,
                  isRecommendListCount:res.data.isRecommendListCount||0,
              });
          }else{
              common.toast(res.msg,'none');
          }
          wx.stopPullDownRefresh();
      });
  },

  goListPage:function (e) {
    let type = e.currentTarget.dataset.type;
    let url='/pages/exhibit-list/list';
      switch (type) {
          case 'want':
              url = url+'?type=want';
              break;
          case 'new':
              url = url+'?type=new';
              break;
          case 'recommend':
              url = url+'?type=recommend';
              break;
      }
    wx.navigateTo({
        url
    });
  },
  goDeail:function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
        url: "/pages/exhibit-detail/detail?id="+id
    });
  },
});
